<?php 
class News_add extends CI_Controller  {
	function __construct()
 {
  	parent::__construct();
	$this->load->model('TB_Menu');
	$this->load->helper(array('form', 'url'));
 }
	function index()
	{
	//	$this->load->view('upload_form', array('error' => ' ' ));
		$Data["TypeList"]=$this->TB_Menu->get_TypeByClassID($_GET["classid"]);
		if($_GET["sign"]=="add")
		{
			$Data["sign"]="news/insert";
		//	$temparr[0]=array("aa"=>(array("Title"=>"","NewsSource"=>"","OrderNum"=>"","Content"=>"")));
				$temparr[0]['NewsID']=0;
			$temparr[0]['Title']="";
			$temparr[0]['NewsSource']="";
			$temparr[0]['OrderNum']="";
			$temparr[0]['Content']="";
			$Data["NewsEntity"]=$temparr;
		}
		else
		{
			$Data["sign"]="news/update";
			$this->load->model('TB_News');
			$Data["temp"]=$this->TB_News->get_NewsByNewsID($_GET["newsid"]);
			$temparr[0]['NewsID']=$_GET["newsid"];
			$temparr[0]['Title']=	$Data["temp"][0]->Title;
			$temparr[0]['NewsSource']=	$Data["temp"][0]->NewsSource;
			$temparr[0]['OrderNum']=	$Data["temp"][0]->OrderNum;
			$temparr[0]['Content']=	$Data["temp"][0]->Content;
			$Data["NewsEntity"]=$temparr;
		}
		$this->load->view('Add_news',$Data);
	}
	function do_upload()
	 {
		  $config['upload_path'] = getcwd().'./uploads/';
		  $config['allowed_types'] = 'gif|jpg|png';
		  $config['max_size'] = '1000';
		  $config['max_width']  = '1024';
		  $config['max_height']  = '768';
		  $config['overwrite']=true;
		  $renamebytime=date('ymdhis');
 		  $config['file_name']=$renamebytime;

		  $this->load->library('upload', $config);
		  $this->upload->initialize($config);
		  $this->config->load('config_global',TRUE);
		  
		  if ( ! $this->upload->do_upload())
		  {
		//	 $this->config->set_item('UploadFileName', '');
		 //  $error = array('error' => $this->upload->display_errors());
		   
		   //$this->load->view('upload_form', $error);
		  } 
		  else
		  {
		  //	  $this->config->set_item('UploadFileName', $renamebytime);
			  // $data = array('upload_data' => $this->upload->data());
			  //$this->load->view('upload_success', $data);

	 		} 
	 }
}